package com.example.bishe.web.b.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bishe.entity.Message;
import com.example.bishe.service.MessageService;
import com.example.bishe.util.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能描述
 *
 * @author: LDH
 * @date: 2023年05月08日 19:39
 */
@RestController
@RequestMapping("/b/message")
@Api(value = "PC端", tags = {"消息通知管理"})
public class MessageController {

    @Autowired
    private MessageService messageService;

    @ApiOperation("查询消息通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "消息id", paramType = "query"),
            @ApiImplicitParam(name = "uid", value = "用户id", paramType = "query"),
            @ApiImplicitParam(name = "context", value = "消息内容", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "通知类型", paramType = "query")
    })
    @GetMapping("/page")
    public RestResult<IPage<Message>> page(
            @RequestParam(required = false,defaultValue = "1")  int pageNum,
            @RequestParam(required = false,defaultValue = "10") int pageSize,
            @RequestParam(required = false) Long id,
            @RequestParam(required = false) Long uid,
            @RequestParam(required = false) String context,
            @RequestParam(required = false) Integer type,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime
    ){
        return RestResult.get_success(messageService.getPage(pageNum,pageSize,id,uid,context,type,startTime,endTime));
    }

    @ApiOperation("管理员新建通知")
    @PostMapping("/add")
    public RestResult<Void> add(@RequestBody Message message){
        messageService.add(message);
        return RestResult.set_success("新建成功！");
    }

    @ApiOperation("管理员删除单个消息通知")
    @DeleteMapping("/one")
    public RestResult<Void> delOne(@RequestBody Message message){
        messageService.add(message);
        return RestResult.set_success("删除成功!");
    }

    @DeleteMapping("/batch")
    public RestResult<Void> delBatch(@RequestBody List<Message> list){
        messageService.delBatch(list);
        return RestResult.set_success("批量删除成功！");
    }
}